import Vue from 'vue';
import VueRouter from 'vue-router';
import Router from 'vue-router';
Vue.use(VueRouter);

const routes = [

  {
    path: '/',
    name: 'Index',
    component: () => import('../view/homeIndex/homeIndex.vue'),
    meta: {
      title: '首页'
    },
    children: [
      {
        path: '/demoItem',
        name: 'demoItem',
        component: () => import('../view/demoItem/demoItem.vue'),
        meta: {
          title: 'demo'
        },
        children: [
          {
            path: '/demo1',
            name: 'demo1',
            children: [
              {
                path: '/demo1/add',
                name: 'demoAdd',
                children: [
                  {
                    path: '/demo1/add/add',
                    name: 'demoAddAdd',
                    component: () => import('../view/demoItem/demoItem.vue'),
                  }, {
                    path: '/demo1/add/detail',
                    name: 'detail',
                    children: [
                      {
                        name: '1',
                        path: '',
                        children: [
                          {
                            name: '3',
                            path: ''
                          }
                        ]
                      }, {
                        name: '2',
                        path: '',
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            path: '/demo2',
            name: 'demo2'
          }
        ]
      }, {
        path: '/demoItem2',
        name: 'demoItem2'
      }
    ]
  }
  , {
    path: '*',
    name: '404',
    component: () => import('../view/404/noFound.vue'),
    meta: {
      title: '404'
    }
  }
];

//解决相同路由情况下跳转报错
const originalPush = Router.prototype.push;
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err);
};


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});

export default router;
